home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 1998 November / IRIX 6.5.2 Base Documentation November 1998.img / usr / share / catman / u_man / cat1 / expr.z / expr
Text File  |  1998-10-20  |  9KB  |  199 lines

  1.  
  2.  
  3.  
  4. eeeexxxxpppprrrr((((1111))))                                                                eeeexxxxpppprrrr((((1111))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      _eeee_xxxx_pppp_rrrr - evaluate arguments as an expression
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      _eeee_xxxx_pppp_rrrr _a_r_g_u_m_e_n_t_s
  13.  
  14. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  15.      The _a_r_g_u_m_e_n_t_s are taken as an expression.  After evaluation, the result
  16.      is written on the standard output.  Terms of the expression must be
  17.      separated by blanks.  Characters special to the shell must be escaped.
  18.      Note that _0000 is returned to indicate a zero value, rather than the null
  19.      string.  Strings containing blanks or other special characters should be
  20.      quoted.  Integer-valued arguments may be preceded by a unary minus sign.
  21.      Internally, integers are treated as 32-bit, 2s complement numbers.  The
  22.      length of the expression is limited to 512 bytes.  _eeee_xxxx_pppp_rrrr processes
  23.      supplementary code set characters according to the locale specified in
  24.      the _LLLL_CCCC______CCCC_TTTT_YYYY_PPPP_EEEE environment variable [see _LLLL_AAAA_NNNN_GGGG on _eeee_nnnn_vvvv_iiii_rrrr_oooo_nnnn(5)].  In regular
  25.      expressions, pattern searches are performed on characters, not bytes, as
  26.      described in _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp(5).
  27.  
  28.      The operators and keywords are listed below.  Characters that need to be
  29.      escaped in the shell [see _ssss_hhhh(1)] are preceded by _\\\\.  The list is in order
  30.      of increasing precedence, with equal precedence operators grouped within
  31.      _{{{{_}}}} symbols.
  32.  
  33.      _e_x_p_r_1 _\\\\_|||| _e_x_p_r_2
  34.           returns the evaluation of _e_x_p_r_1 if it is neither null nor _0000,
  35.           otherwise returns the evaluation of _e_x_p_r_2.
  36.  
  37.      _e_x_p_r_1 _\\\\_&&&& _e_x_p_r_2
  38.           returns the evaluation of _e_x_p_r_1 if neither expression evaluates to
  39.           null or _0000, otherwise returns _0000.
  40.  
  41.           Returns the result of a decimal integer comparison if both arguments
  42.           are integers; otherwise, returns the result of a string comparison
  43.           using the locale-specific collation sequence. The result of each
  44.           comparison will be _1111 if the specified relationship is true, or _0000 if
  45.           the relationship is false.
  46.  
  47.      _e_x_p_r_1 { _====, _\\\\_>>>>, _\\\\_>>>>_====, _\\\\_<<<<, _\\\\_<<<<_====, _!!!!_==== } _e_x_p_r_2
  48.           returns the result of an integer comparison if both arguments are
  49.           integers, otherwise returns the result of a lexical comparison.
  50.  
  51.      _e_x_p_r_1 { _++++, _---- } _e_x_p_r_2
  52.           addition or subtraction of decimal integer-valued arguments.
  53.  
  54.      _e_x_p_r_1 { _\\\\_****, _////, _%%%% } _e_x_p_r_2
  55.           multiplication, division, or remainder of the decimal integer-valued
  56.           arguments.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. eeeexxxxpppprrrr((((1111))))                                                                eeeexxxxpppprrrr((((1111))))
  71.  
  72.  
  73.  
  74.      _e_x_p_r_1 _:::: _e_x_p_r_2
  75.           The matching operator _:::: compares _e_x_p_r_1 with _e_x_p_r_2, which must be a
  76.           regular expression.  Regular expression syntax is defined is defined
  77.           in the _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp_((((_5555_)))) man page under the section titled: _B_a_s_i_c _R_e_g_u_l_a_r
  78.           _E_x_p_r_e_s_s_i_o_n, Normally, the matching operator returns the number of
  79.           bytes matched (_0000 on failure).  Alternatively, if the pattern
  80.           contains at least one regular expression subexpression [\( . . .\)],
  81.           the string corresponding to \1 will be returned.
  82.  
  83.      The use of string arguments _llll_eeee_nnnn_gggg_tttt_hhhh, _ssss_uuuu_bbbb_ssss_tttt_rrrr, _iiii_nnnn_dddd_eeee_xxxx or _mmmm_aaaa_tttt_cccc_hhhh produces
  84.      unspecified results.
  85.  
  86. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  87.      Add 1 to the shell variable _aaaa:
  88.  
  89.           _aaaa_====_````_eeee_xxxx_pppp_rrrr _$$$$_aaaa _++++ _1111_````
  90.  
  91.      The following example emulates _bbbb_aaaa_ssss_eeee_nnnn_aaaa_mmmm_eeee(1)-it returns the last segment of
  92.      the path name _$$$$_aaaa.  For _$$$$_aaaa equal to either _////_uuuu_ssss_rrrr_////_aaaa_bbbb_cccc_////_ffff_iiii_llll_eeee or just _ffff_iiii_llll_eeee, the
  93.      example returns _ffff_iiii_llll_eeee.  (Watch out for _//// alone as an argument:  _eeee_xxxx_pppp_rrrr takes
  94.      it as the division operator; see the NOTES below.)
  95.  
  96.           _eeee_xxxx_pppp_rrrr _$$$$_aaaa _:::: _''''_...._****_////_\\\\_((((_...._****_\\\\_))))_'''' _\\\\_|||| _$$$$_aaaa
  97.  
  98.      Here is a better version of the previous example.  The addition of the _////_////
  99.      characters eliminates any ambiguity about the division operator and
  100.      simplifies the whole expression.
  101.  
  102.           _eeee_xxxx_pppp_rrrr _////_////_$$$$_aaaa _:::: _''''_...._****_////_\\\\_((((_...._****_\\\\_))))_''''
  103.  
  104.      Return the number of characters in _$$$$_VVVV_AAAA_RRRR:
  105.  
  106.           _eeee_xxxx_pppp_rrrr _$$$$_VVVV_AAAA_RRRR _:::: _''''_...._****_''''
  107.  
  108. FFFFIIIILLLLEEEESSSS
  109.      _////_uuuu_ssss_rrrr_////_llll_iiii_bbbb_////_llll_oooo_cccc_aaaa_llll_eeee_////_l_o_c_a_l_e_////_LLLL_CCCC______MMMM_EEEE_SSSS_SSSS_AAAA_GGGG_EEEE_SSSS_////_uuuu_xxxx_cccc_oooo_rrrr_eeee_...._aaaa_bbbb_iiii
  110.           language-specific message file [See _LLLL_AAAA_NNNN_GGGG on _eeee_nnnn_vvvv_iiii_rrrr_oooo_nnnn (5).]
  111.  
  112. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  113.      _rrrr_eeee_gggg_cccc_oooo_mmmm_pppp(5), _ssss_hhhh(1)
  114.  
  115. SSSSTTTTDDDDOOOOUUUUTTTT
  116.      _e_x_p_r will evaluate the expression and write the result to standard
  117.      output. The character _0000 will be written to indicate a zero value and
  118.      nothing will be written to indicate a null string.
  119.  
  120. SSSSTTTTDDDDEEEERRRRRRRR
  121.      Used only for diagnostic messages.
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. eeeexxxxpppprrrr((((1111))))                                                                eeeexxxxpppprrrr((((1111))))
  137.  
  138.  
  139.  
  140. DIAGNOSTICS
  141.      As a side effect of expression evaluation, _eeee_xxxx_pppp_rrrr returns the following
  142.      exit values:
  143.       0   if the expression is neither null nor _0000
  144.       1   if the expression is null or _0000
  145.       2   for invalid expressions.
  146.      >2   An error occurred.
  147.  
  148.      _ssss_yyyy_nnnn_tttt_aaaa_xxxx _eeee_rrrr_rrrr_oooo_rrrr     for operator/operand errors
  149.      _nnnn_oooo_nnnn_----_nnnn_uuuu_mmmm_eeee_rrrr_iiii_cccc _aaaa_rrrr_gggg_uuuu_mmmm_eeee_nnnn_tttt
  150.                       if arithmetic is attempted on such a string
  151.  
  152. NNNNOOOOTTTTEEEESSSS
  153.      After argument processing by the shell, _eeee_xxxx_pppp_rrrr cannot tell the difference
  154.      between an operator and an operand except by the value.  If _$$$$_aaaa is an _====,
  155.      the command:
  156.  
  157.           _eeee_xxxx_pppp_rrrr _$$$$_aaaa _==== _''''_====_''''
  158.  
  159.      looks like:
  160.  
  161.           _eeee_xxxx_pppp_rrrr _==== _==== _====
  162.  
  163.      as the arguments are passed to _eeee_xxxx_pppp_rrrr (and they are all taken as the _====
  164.      operator).  The following works:
  165.  
  166.           _eeee_xxxx_pppp_rrrr _XXXX_$$$$_aaaa _==== _XXXX_====
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.